

#include <iostream>
#include <vector>
#include <algorithm>

int removeElement(std::vector<int>& v, int value)
{
	int* p = &v[0];
	int* q = &v[v.size() - 1];

	while (p < q)
	{
		if (*p != value)
		{
			p++;
			continue;
		}
		if (*q == value)
		{
			q--;
			continue;
		}
		std::swap(*p, *q);
		 
	}

	return p - &v[0];

}



int main(void)
{
	int value = 10;
	std::vector<int> v = { 10, 20 ,40, 20 ,30, 10, 100, 10, 40, 10 };
	

	std::for_each(v.begin(), v.end(), [](int t) {std::cout << t << "   "; });
	std::cout << std::endl;
	int counts = removeElement(v, value);
	std::for_each(v.begin(), v.begin()+counts, [](int t) {std::cout << t << "   "; });






	return 0;
}
